<?php 

class errorhandler {
	public $_debug;
	public $_result;
	public $_errorFlag;

	function __construct() {
		$this->_result = array();
		$this->_errorFlag = 0;
		$this->_debug = 1;
	}

	/**
	 * Enter description here ...
	 * @param string $request - admin_page
	 * @param string $message - uses $lang
	 * @param __LINE__ $line
	 * @param __FILE__ $file
	 * @param string $details - $sql,etc
	 * @param string $code - used for json checks
	 * @param string $header - custom header message, uses $lang
	 */
	function message_die($request,$message,$line,$file,$details = '',$code = -1,$header = '',$status = 'error') {

		if(!$this->_errorFlag && $code != 1) {
			$this->_errorFlag = 1;
			$this->_result['code'] = $code;
			$this->_result['message'] = ($this->lang[$request][$status][$message] != '') ? $this->lang[$request][$status][$message] : ($this->lang[$status][$message] != '' ? $this->lang[$status][$message]: $message);
			$this->_result['line'] = $line;
			$this->_result['file'] = basename($file);
			$this->_result['details'] = ($this->_debug) ? $details : '';
			$this->_result['error'] = $this->_errorFlag;
			$this->_result['header'] = ($this->lang[$request][$status]['header'] != '') ? $this->lang[$request][$status]['header'] : $this->lang[$status]['header'];
		}
		
		if(!$this->_errorFlag && $code == 1)
		{
			$this->_result['code'] = $code;
			$this->_result['message'] = ($this->lang[$request][$status][$message] != '') ? $this->lang[$request][$status][$message] : ($this->lang[$status][$message] != '' ? $this->lang[$status][$message]: $message);
			$this->_result['details'] = ($this->_debug) ? $details : '';
			$this->_result['error'] = $this->_errorFlag;
			$this->_result['header'] = ($this->lang[$request][$status]['header'] != '') ? $this->lang[$request][$status]['header'] : $this->lang[$status]['header'];
		}

	}

}